package com.los;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static java.util.stream.Collectors.toList;

/**
 * @program: java8
 * @description: 流只能被消费一次
 * @author: Yujuan
 * @create: 2018-06-13 16:28
 **/
public class SimpleStream {
    public static void main(String[] args) {
        List<Dish> menu = Arrays.asList(
                new Dish("pork", false, 800, Dish.Type.MEAT),
                new Dish("beef", false, 700, Dish.Type.MEAT),
                new Dish("chicken", false, 400, Dish.Type.MEAT),
                new Dish("french fries", true, 530, Dish.Type.OTHER),
                new Dish("rice", true, 350, Dish.Type.OTHER),
                new Dish("season fruit", true, 120, Dish.Type.OTHER),
                new Dish("pizza", true, 550, Dish.Type.OTHER),
                new Dish("prawns", false, 300, Dish.Type.FISH),
                new Dish("salmon", false, 450, Dish.Type.FISH));
//        List<String> strings=menu.stream().map(Dish::getName).collect(toList());
//        System.out.println(strings.stream().count());
//        menu.parallelStream().forEach(dish -> System.out.println(dish.getName()));

        List<String> strings=menu.stream().filter(dish -> {
            System.out.println("filter:"+dish.getName());
            return dish.getCalories()>500;
        }).map(dish -> {
            System.out.println("map:"+dish.getName());
            return dish.getName();
        }).limit(3).collect(toList());
        System.out.println(strings);

    }
}
